﻿namespace GSC.WebControls
{
    using System;
    using System.Collections.Generic;
    using System.Web.UI.Design;
    using System.Web.UI.Design.WebControls;
    using System.ComponentModel;
    using System.Web.UI;
    using System.Web;
    using System.Web.UI.WebControls;
    using System.IO;
    using System.ComponentModel.Design;
    using System.Web.UI.HtmlControls;
    class BackgroundCopyrightControlDesigner : CompositeControlDesigner
    {
        private BackgroundCopyrightControl _Copyright;

        public override TemplateGroupCollection TemplateGroups
        {
            get
            {
                TemplateGroupCollection collection = new TemplateGroupCollection();
                TemplateGroup group;
                TemplateDefinition template;
                BackgroundCopyrightControl control;
                control = (BackgroundCopyrightControl)Component;
                //
                group = new TemplateGroup("ContentTemplate");
                template = new TemplateDefinition(this, "ContentTemplate", control, "ContentTemplate", false);
                group.AddTemplateDefinition(template);
                collection.Add(group);
                return collection;
            }
        }
        /// <summary>
        /// </summary>
        /// <param name="Component"></param>
        public override void Initialize(IComponent Component)
        {
            base.Initialize(Component);
            this._Copyright = (BackgroundCopyrightControl)Component;
            SetViewFlags(ViewFlags.TemplateEditing, true);
        }
        /// <summary>
        /// </summary>
        /// <returns></returns>
        public override string GetDesignTimeHtml()
        {
            try
            {
                //
                this.CreateChildControls();
                Panel p = new Panel();
                p.Style["overflow"] = "hidden";
                p.Style["background-position"] = "center";
                p.Style["background-repeat"] = "no-repeat";
                if (string.IsNullOrEmpty(_Copyright.BackImage))
                    p.Style["background-image"] = "url(" + _Copyright.ResolveClientUrl(_Copyright.GetWebResourceUrl("BackgroundCopyrightControl.gif")) + ")";
                else
                    p.Style["background-image"] = "url(" + _Copyright.ResolveClientUrl(_Copyright.BackImage) + ")";
                p.Width = this._Copyright.Width;
                p.Height = this._Copyright.Height;
                foreach (Control item in _Copyright.Controls)
                {
                    p.Controls.Add(item);
                }
                StringWriter sw = new StringWriter();
                HtmlTextWriter hw = new HtmlTextWriter(sw); ;
                p.RenderControl(hw);
                return sw.ToString();
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
        }
    }
}